package com.gegong.imr.client.tasks;

import okhttp3.Response;

public class TaskException extends Exception {

    public TaskException(String message) {
        super(message);
    }

    private TaskException(String message, Throwable cause) {
        super(message, cause);
    }

    public static TaskException forException(String operation, Throwable cause) {
        return new TaskException(String.format("[%s]-异常", operation), cause);
    }


    public static TaskException forFailure(String operation, Response response) {
        return new TaskException(String.format("[%s]-HTTP异常{%s}", operation, response));
    }


    public static TaskException forEmptyBody(String operation, Throwable cause) {
        return new TaskException(String.format("[%s]响应内容为空", operation), cause);
    }

    public static TaskException forBusiness(String operation, int code, String message) {
        return new TaskException(String.format("[%s]业务异常,代码=%d,消息=%s", operation, code, message));
    }
}
